Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/service/src/androidMain/kotlin/org/meshtastic/core/service/MeshServiceStarter.kt bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 2.83 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.service

Tff7b72import T7ee787android.content.Context
Tff7b72import T7ee787co.touchlab.kermit.Logger

T8b949e/**
* Starts [MeshService] as a foreground service so the radio link stays alive for the duration of the connection.
*
* The start is gated on [ForegroundStartPolicy]: when the platform would reject it we do not call
* `startForegroundService()` at all. That matters for more than tidiness — a rejected start still leaves
* ActivityManager expecting the service to reach the foreground, and the resulting watchdog kills the process. Not
* asking is the only way to be sure.
*
* There is deliberately no retry. Every context that can legally promote this app to the foreground already has its own
* trigger, and the dominant one — the user opening the app — fires on every `MainActivity.onStart()`. A background
* retry has no exemption the original caller lacked, so it can only fail again.
*/
Tff7b72fun Te6edf3MeshServiceTb4b4b4.Td2a8ffCompanionTb4b4b4.Te6edf3startServiceTb4b4b4(Te6edf3contextTb4b4b4: Te6edf3ContextTb4b4b4, Te6edf3triggerTb4b4b4: Te6edf3ServiceStartTriggerTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3appInForeground Tff7b72= Te6edf3isAppInForegroundTb4b4b4(Tb4b4b4)
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3ForegroundStartPolicyTb4b4b4.Te6edf3isForegroundStartAllowedTb4b4b4(Te6edf3triggerTb4b4b4, Te6edf3appInForegroundTb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3i Tb4b4b4{
Ta5d6ff"Ta5d6ffSkipping MeshService start: trigger=Tffd700$Te6edf3triggerTa5d6ff is not permitted to start a foreground service while Ta5d6ff" Tff7b72+
Ta5d6ff"Ta5d6ffbackgrounded. Waiting for the next user-visible start.Ta5d6ff"
Tb4b4b4}
Tff7b72return
Tb4b4b4}

Te6edf3LoggerTb4b4b4.Te6edf3i Tb4b4b4{ Ta5d6ff"Ta5d6ffStarting MeshService (trigger=Tffd700$Te6edf3triggerTa5d6ff, appInForeground=Tffd700$Te6edf3appInForegroundTa5d6ff)Ta5d6ff" Tb4b4b4}
Tff7b72try Tb4b4b4{
Te6edf3contextTb4b4b4.Te6edf3startForegroundServiceTb4b4b4(Te6edf3createIntentTb4b4b4(Te6edf3contextTb4b4b4)Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3exTb4b4b4: Te6edf3IllegalStateExceptionTb4b4b4) Tb4b4b4{
T8b949e// ForegroundServiceStartNotAllowedException extends IllegalStateException (via ServiceStartNotAllowedException)
T8b949e// and only exists from API 31; catching the supertype keeps this call site free of an API-gated class
T8b949e// reference. The service was never created, so there is nothing to tear down here.
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3exTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffRejected MeshService foreground start (trigger=Tffd700$Te6edf3triggerTa5d6ff)Ta5d6ff" Tb4b4b4}
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3exTb4b4b4: Te6edf3SecurityExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3exTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffMissing permission for MeshService foreground start (trigger=Tffd700$Te6edf3triggerTa5d6ff)Ta5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.05s